package com.intct.flink;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.time.Duration;

/**
 * @author gufg
 * @since 2025-06-25 09:51
 */
public class FromFileGetData {
    public static void main(String[] args) throws Exception {
        // 创建环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        // 获取数据源
        FileSource<String> fileSource = FileSource.forRecordStreamFormat(
                new TextLineInputFormat(),
                new Path("D:\\ResourceCodes\\edu-system-teaching\\intct81\\src\\main\\resources\\stu.txt")
                )
                .monitorContinuously(Duration.ofSeconds(1L))
                .build();

        DataStreamSource<String> dataStreamSource = env.fromSource(fileSource, WatermarkStrategy.noWatermarks(), "file-source");

        // 转换

        // 输出
        dataStreamSource.print();

        // 启动作业
        env.execute();
    }
}
